<?php
!defined('P_W') && exit('Forbidden');
require_once R_P.'lib/base/related.php';
class PW_HouseImageRelated extends Related {
	var $service;
	function PW_HouseImageRelated() {
		parent::__construct();
		$this->service = House::loadClass('houseimagetype'); /* @var $imageTypeService PW_HouseImageType */;
	}
	function initRang($piece) {
		if ($this->ifLoop) return $this->ifLoopRang($piece);
		$options	= $this->_getImageTypeOptions();
		$piece['rang']	= str_replace('<option value="'.$piece['rang'].'">','<option value="'.$piece['rang'].'" selected>',$options);
		$piece['rang']	= '设置图片类型：'.'<select name="rang['.$piece['id'].']">'.$piece['rang'].'</select>';
		return $piece;
	}
	
	
	function _getImageTypeOptions() {
		//@include(D_P.'data/bbscache/forum_cache.php');
		
		$topTypes = $this->service->getTopTypes();
		$secendTypes = $this->service->getSecendTypes();
		$options = '<option value=""></option>';
		foreach ($topTypes as $key => $top) {
			$options .= '<option value="'.$top['id'].'">'.$top['name'].'</option>';
			if($secendTypes[$key]){
				foreach ($secendTypes[$key] as $k=>$secend) {
					$options .= '<option value="'.$secend['id'].'">&nbsp; &nbsp;|-'.$secend['name'].'</option>';
				}
			}
		}
		
		return $options;
	}
}
?>